<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>已完成订单下的菜品</title>
    <style>
        div {
            position: absolute;
            top: 30%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
        }
        table,tr,th,td{
            border: 1px solid #5fbdcb;
        }
        table{
            border-collapse: collapse;
        }
    </style>
</head>
<body>
<div>
    <table></table>
    <br>
    <a href="" id="a">返回</a>
</div>
<script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js"></script>
<script>
    function getParam(url, name) {
        try {
            let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            let r = url.split('?')[1].match(reg);
            if (r != null) {
                return r[2];
            }
            return "";
        } catch (e) {
            return "";
        }
    }

    let url = window.location.href;
    let storeId = getParam(url, 'storeId')
    let orderId = getParam(url, 'orderId');
    $(function () {
        let a = document.querySelector('#a');
        a.href = 'ProcessOrderPage.jsp?storeId=' + storeId;
        $.ajax({
            url: "http://localhost:8080/order.do",
            type: "post",
            data: {
                orderId: orderId,
                method: 'selectHaveOrder'
            },
            dataType: "text",
            success: function (data) {
                let parse = JSON.parse(data);
                let table = document.querySelector('table');
                for (let i = 0; i < parse.length; i++) {
                    let tr = document.createElement('tr');
                    table.appendChild(tr);
                    let th1 = document.createElement('th');
                    tr.appendChild(th1);
                    th1.innerText = '菜品名称';
                    let td1 = document.createElement('td');
                    tr.appendChild(td1);
                    td1.innerText = parse[i].dishName;
                }
            }
        })
    })
</script>
</body>
</html>
